package edu.pe.cayetano.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import ws.synopsis.frmwrk.common.InitParameter;
import edu.pe.cayetano.framework.DAOException;
import edu.pe.cayetano.model.bean.ParametroBean;


public class ConfigurationDAO extends BaseDAO{

	
	public ConfigurationDAO(Connection cnx) {
		super(cnx);
	}
	
	public ArrayList<ParametroBean> getParametros(String nombre) throws Exception{

		String 				schema			= InitParameter.getInstance().getDatabaseSchema();
		ArrayList<ParametroBean> 			lista		 	= new ArrayList<ParametroBean>();
		PreparedStatement   pstmt 		 	= null;
		ResultSet 			rs 			 	= null;
		ParametroBean 		parametroTO		= null;
		
			try{
				StringBuffer query  = new StringBuffer();
				query.append(" SELECT  cod_parametro,nombre,valor,valor2 " +
							 " from "+schema+".parametros where nombre='"+nombre.trim()+"'");    
				pstmt = getConnection().prepareStatement(query.toString());
				rs=pstmt.executeQuery();
				while(rs.next()){
					parametroTO=new ParametroBean();
					parametroTO.setCodigo(rs.getInt(1));
					parametroTO.setNombre(rs.getString(2));
					parametroTO.setValor1(rs.getString(3));
					parametroTO.setValor2(rs.getString(4));
					lista.add(parametroTO);
				}
			}catch(Exception e){
				throw new DAOException(e.getMessage());
			}finally{
				try{
					try{pstmt.close();}catch(Exception e){}
					try{rs.close();}catch(Exception e){}
				}catch(Exception e1){}
			}
	return lista;
	}
}
